package cc.siyecao.mapper;

import lombok.Data;

import java.util.Collection;

@Data
public class Criterion {

    private final String condition;

    private Object value;

    private Object secondValue;

    private boolean noValue;

    private boolean singleValue;

    private boolean betweenValue;

    private boolean listValue;

    private boolean orValue;

    public Criterion(String condition, Object value) {
        this( condition, value, null );
    }

    public Criterion(String condition) {
        this.condition = condition;
        this.noValue = true;
    }

    public Criterion(String condition, Object value, String typeHandler) {
        super();
        this.condition = condition;
        this.value = value;
        if (value instanceof Collection<?>) {
            if (condition != null) {
                this.listValue = true;
            } else {
                this.orValue = true;
            }
        } else {
            this.singleValue = true;
        }
    }

    public Criterion(String condition, Object value, Object secondValue, String typeHandler) {
        super();
        this.condition = condition;
        this.value = value;
        this.secondValue = secondValue;
        this.betweenValue = true;
    }

    public Criterion(String condition, Object value, Object secondValue) {
        this( condition, value, secondValue, null );
    }

}
